import * as TYPES from "../action-types";
import _ from "../../utils/utils";

const initial = {
  storeList: null,
};

function storeReducer(state = initial, action) {
  state = _.clone(state);
  switch (action.type) {
    case TYPES.GET_STORE_LISTS:
      state.storeList = action.list;
      break;
    case TYPES.STORE_REMOVE:
      if (Array.isArray(state.list)) {
        state.list = state.list.filter((item) => {
          return +item.id !== +action.id;
        });
      }
      break;
    default:
  }
  return state;
}

export default storeReducer;
